//
//  BaseInterface.m
//  EverydayNews
//
//  Created by 李沛池 on 2017/8/6.
//  Copyright © 2017年 Godlike. All rights reserved.
//

#import "ENInterface.h"
#import "LPCHTTPSessionManager.h"
#import "LPCTools.h"

@implementation ENInterface

//读取广告
+ (void)loadADWithPageNum:(NSInteger)pageNum
                    block:(void (^)(NSDictionary *, NSError *))block
{
    [LPCHTTPSessionManager getDataFromParametersAndHideHUD:@{@"num":@(pageNum)}
                                                 urlSuffix:@"banner/fetch"
                                                   success:^(NSDictionary *dic) {
                                                       if (block) {
                                                           block(dic,nil);
                                                       }
                                                   }
                                                   failure:nil
                                                       hud:nil];
}

//获取股票列表
+ (void)getSharesListWithMarket:(NSString *)market
                           page:(NSInteger)page
                        success:(void (^)(NSDictionary *json))success
                        failure:(void (^)(NSError *error))failure
{
    [LPCHTTPSessionManager aliyunDataWithPath:@"/stocklist"
                                       querys:@{@"market":market,
                                                @"page":@(page)}
                                      success:success
                                      failure:failure];
}

//获取股票详情
+ (void)getSharesDetailListWithStocks:(NSString *)stocks
                              success:(void (^)(NSDictionary *json))success
                              failure:(void (^)(NSError *error))failure
{
    [LPCHTTPSessionManager aliyunDataWithPath:@"/batch-real-stockinfo"
                                       querys:@{@"needIndex":@(1),
                                                @"stocks":stocks}
                                      success:success
                                      failure:failure];
}

//搜索股票
+ (void)searchSharesListWithWord:(NSString *)word
                         success:(void (^)(NSDictionary *json))success
                         failure:(void (^)(NSError *error))failure
{
    NSDictionary *query;
    if ([LPCTools deptNumInputShouldNumber:word]) {
        query = @{@"code":word};
    }else if ([LPCTools isChinese:word]) {
        //中文转换
        query = @{@"name":[word stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]};
    }else if ([LPCTools pureLetters:word]) {
        query = @{@"pinyin":word};
    }else {
        failure(nil);
        return;
    }
    [LPCHTTPSessionManager aliyunDataWithPath:@"/name-to-stockinfo"
                                       querys:query
                                      success:success
                                      failure:failure];
}

@end
